

using System.Drawing;

using Font=SharpWind.Resources.Font;
using Microsoft.DirectX.Direct3D;

namespace SharpWind.Gui.Controls
{
	public class Label : Control
	{
		protected string text = string.Empty;

		protected Font font = null;

		protected Color textColor = Color.Black;

		protected TextAlign textAlign = TextAlign.MiddleLeft;

		protected bool wordBreak = false;

		public Label()
		{
			Text = "label";
			Size = new SizeF( 35, 20 );
		}

		internal override void Render()
		{
			if( Visible )
			{
				if( this.font != null && this.text != null && this.text != string.Empty )
				{
					DrawTextFormat format = TextAlignToTextFormat();
					if( wordBreak )
					{
						format |= DrawTextFormat.WordBreak;
					}

					this.font.DrawText( this.text,
					                    new Rectangle( new Point( (int)Location.X, (int)Location.Y ),
					                                   new Size( (int)Size.Width, (int)Size.Height ) ), format, this.textColor );
				}
			}
		}

		private DrawTextFormat TextAlignToTextFormat()
		{
			switch( this.textAlign )
			{
				case TextAlign.TopLeft:
				{
					return DrawTextFormat.Top | DrawTextFormat.Left;
				}

				case TextAlign.TopCenter:
				{
					return DrawTextFormat.Top | DrawTextFormat.Center;
				}

				case TextAlign.TopRight:
				{
					return DrawTextFormat.Top | DrawTextFormat.Right;
				}

				case TextAlign.MiddleLeft:
				{
					return DrawTextFormat.VerticalCenter | DrawTextFormat.Left;
				}

				case TextAlign.MiddleCenter:
				{
					return DrawTextFormat.VerticalCenter | DrawTextFormat.Center;
				}

				case TextAlign.MiddleRight:
				{
					return DrawTextFormat.VerticalCenter | DrawTextFormat.Right;
				}

				case TextAlign.BottomLeft:
				{
					return DrawTextFormat.Bottom | DrawTextFormat.Left;
				}

				case TextAlign.BottomCenter:
				{
					return DrawTextFormat.Bottom | DrawTextFormat.Center;
				}

				case TextAlign.BottomRight:
				{
					return DrawTextFormat.Bottom | DrawTextFormat.Right;
				}
			}

			return DrawTextFormat.None;
		}

		public string Text
		{
			get
			{
				return this.text;
			}
			set
			{
				this.text = value;
			}
		}

		public TextAlign TextAlign
		{
			get
			{
				return this.textAlign;
			}
			set
			{
				this.textAlign = value;
			}
		}

		public Font Font
		{
			get
			{
				return this.font;
			}
			set
			{
				this.font = value;
			}
		}

		public Color TextColor
		{
			get
			{
				return this.textColor;
			}
			set
			{
				this.textColor = value;
			}
		}

		public bool WordBreak
		{
			get
			{
				return this.wordBreak;
			}
			set
			{
				this.wordBreak = value;
			}
		}
	}
}
